class Mobile::PayController < ApplicationController    
    protect_from_forgery with: :null_session
    include PrintOrder
    
    def index
      result = Hash.from_xml(request.body.read)["xml"]
      if WxPay::Sign.verify?(result)
        if result["result_code"] == "SUCCESS"
          trade_no = result["out_trade_no"]
          order = Order.find_by_order_number(trade_no)
          order.is_pay = true
          order.status = Order::SUCCESS
          order.save
          content = generate_content order
          printers_print order.restaurant,content
          render :xml => {return_code: "SUCCESS"}.to_xml(root: 'xml',dasherize: false) and return
        end  
      end    
      render :xml => {return_code: "FAIL",return_msg:"签名失败"}.to_xml(root:'xml',dasherize: false)    
    end    
end
